<template>
	<view>
		<div>
			<navitop>
				<i class="iconfont" slot="left-slot" @click="outlot">&#xe667;</i>
				<span slot="center-slot">私有云设置</span>
				<!-- <i class="iconfont " slot="right-slot" @click="add">确定</i> -->
			</navitop>
		</div>
		<div :style="'margin-top:' + nv_height">
			<div class="set_out">
				<div class="set_otu">
					<div class="set_inp">
						<div class="set_inp_one">
							<input  placeholder="登录地址" v-model="http_name">
						</div>
						<div class="wet_inp_tow">
							<input  placeholder="端口" v-model="http_port">
						</div>
					</div>
					<div class="set_fiexd"  @click="set_cloud">恢复公有云</div>
					<div class="set_but">
						<button @click="set_leter">保存</button>
					</div>
				</div>
			</div>
		</div>
	
	</view>
</template>

<script>
import navitop from '@/components/common/navi-top'
export default {
	components: {
		navitop
	},
	data(){
		return {
			nv_height: '',	// 顶部距离
			http_name: '',	// 获取用户输入地址
			http_port: '',	// 获取端口
		}
	},
	mounted() {
		this.nv_height = uni.getSystemInfoSync().statusBarHeight + 65 + 'px';
		
		let _this = this; 
		
		this.http_name = uni.getStorageSync('curl_port').curlname;
		
		this.http_port = uni.getStorageSync('curl_port').curlport;

	},
	methods: {
		outlot(){
			uni.navigateTo({
				url: '/components/user/user-dl'
			})
		},
		set_leter(){
			let runData = {curlname:this.http_name,curlport:this.http_port};
			if(!this.http_name){
				uni.showToast({
					title: '请输入地址！',
					icon: 'error'
				})
			}else if(!this.http_port){
				uni.showToast({
					title: '请输入端口！',
					icon: 'error'
				})
			}else {
				
				uni.removeStorageSync('curl_port_sort')
				
				uni.setStorageSync('curl_port', runData);
				
				uni.showToast({
					title: '保存成功！'
				})
				setTimeout(()=> {
					uni.navigateTo({ 
						url: '/components/user/user-dl'
					})
				},1600)
			}
		},
		set_cloud(){
			let _this = this;
			uni.showModal({
				title: '提示！',
				content: '确定要恢复吗？',
				success(res){
				if (res.confirm) {
						
						uni.removeStorageSync('curl_port')
						
						uni.setStorageSync('curl_port_sort', 'api.sibanyun.com:8000');
						
						uni.showToast({
							title: '恢复成功！'
						})
						setTimeout(() => {
							uni.navigateTo({
								url: '/components/user/user-dl'
							})
						},1600)
						
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			})
		}
	}
}	
</script>

<style scoped lang="scss">
	.set_out {
		background-color: #fff;
	}
	
	.set_otu {
		width: 90%;
		margin: auto;
	}
	
	.set_inp {
		display: flex;
		padding: 50px 0 10px 0;
		input {
			width: 95%;
			border: 1px solid #cacaca;
		}
	}
	
	.set_inp_one {
		width: 70%;
	}
	
	.wet_inp_tow {
		width: 25%;
	}
	
	.set_but {
		padding: 60px 0 40px 0;
		button{
			color: #fff;
			background-color: #587bef;
		}
	}

	.set_txt {
		color: #a3a3a3;
		font-size: 16px;
	}
	.set_fiexd {
		width: 100%;
		color: #9ab2ff;
		font-size: 12px;
	}
</style>
